package com.qianfeng.controller;

import com.qianfeng.dto.Page;
import com.qianfeng.dto.Result;
import com.qianfeng.entity.Student;
import com.qianfeng.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@ResponseBody
@CrossOrigin
@RequestMapping(value = "/student")
@Controller
public class StudentController {

    @Autowired
    private StudentService studentService;

    @RequestMapping(value = "/addStudent")
    public Result addStudent(@RequestBody Student student){
        studentService.addStudent(student);
        Result result = new Result();
        return result;
    }

    /**
     * 删除角色
     * @param studentId
     * @return
     */
    @RequestMapping(value = "/deleteStudent")
    public Result deleteStudent(Integer studentId){
        studentService.deleteStudent(studentId);
        Result result = new Result();
        return result;
    }

    /**
     * 更新角色
     * @param student
     * @return
     */
    @RequestMapping(value = "/updateStudent")
    public Result updateStudent(@RequestBody Student student){
        studentService.updateStudent(student);
        Result result = new Result();
        return result;
    }



    /**
     * 更新角色
     * @param studentId
     * @return
     */
    @RequestMapping(value = "/getListByStudentId")
    public Result getListByStudentId(Integer studentId){
        List<Student> listByStudentId = studentService.getListByStudentId(studentId);
        Result result = new Result();
        result.setData(listByStudentId);
        return result;
    }

    @RequestMapping(value = "/getStudentPage")
    public Result getStudentPage(Integer pageNo,Integer pageSize){
        if(pageNo==null){
            pageNo=1;
        }
        if(pageSize==null){
            pageSize=5;
        }
        Page page = studentService.getStudentPage(pageNo,pageSize);
        Result result = new Result();
        result.setData(page);
        return result;

    }
}
